package com.netintech.project.system.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.netintech.core.web.domain.RequestResult;
import com.netintech.project.system.domain.dto.FindNotRecordPeriodDto;
import com.netintech.project.system.service.HikSdkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author luda
 * @date 2020/8/3 14:14
 */
@Slf4j
@RestController
@RequestMapping("api")
public class ApiController {
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    @Autowired
    private HikSdkService hikSdkService;


    /**
     * 页面通知设备，视频正在播放，心跳
     *
     * @return
     */
    @RequestMapping("queryRecordContinuity")
    public RequestResult queryRecordContinuity(@RequestBody FindNotRecordPeriodDto findNotRecordPeriodDto) {
        try {
            return hikSdkService.queryRecordContinuity(findNotRecordPeriodDto.getDeviceIp(), findNotRecordPeriodDto.getPort(),
                    findNotRecordPeriodDto.getUserName(), findNotRecordPeriodDto.getPassword(), findNotRecordPeriodDto.getStartTime(),
                    findNotRecordPeriodDto.getEndTime(), findNotRecordPeriodDto.getChannelNum(), findNotRecordPeriodDto.getUseCard());
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return RequestResult.error(e.getMessage());
        }
    }


    /**
     * 函数:      "注册"  按钮单击响应函数
     * 函数描述:	注册登录设备
     *
     * @param evt
     */
//    private void jButtonLoginActionPerformed(java.awt.event.ActionEvent evt) {
//        //注册之前先注销已注册的用户,预览情况下不可注销
//        if (bRealPlay) {
//            JOptionPane.showMessageDialog(this, "注册新用户请先停止当前预览!");
//            return;
//        }
//
//        if (lUserID.longValue() > -1) {
//            //先注销
//            hCNetSDK.NET_DVR_Logout_V30(lUserID);
//            lUserID = new NativeLong(-1);
//            m_iTreeNodeNum = 0;
//            m_DeviceRoot.removeAllChildren();
//        }
//        //注册
//        m_sDeviceIP = jTextFieldIPAddress.getText();//设备ip地址
//        m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
//        int iPort = Integer.parseInt(jTextFieldPortNumber.getText());
//        lUserID = hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP,
//                (short) iPort, jTextFieldUserName.getText(), new String(jPasswordFieldPassword.getPassword()), m_strDeviceInfo);
//        System.out.println("注册失败错误码：" + hCNetSDK.NET_DVR_GetLastError());
//
//        long userID = lUserID.longValue();
//        if (userID == -1) {
//            m_sDeviceIP = "";//登录未成功,IP置为空
//            JOptionPane.showMessageDialog(ClientDemo.this, "注册失败");
//        } else {
//            CreateDeviceTree();
//        }
//    }


}
